package com.panda.common.dao;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.panda.common.util.Pager;

/**
 * dao层基类，该类不注入到spring中
 */
@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends JpaSpecificationExecutor<T>, 
		PagingAndSortingRepository<T, ID>, JpaRepository<T,ID>{
	
	T queryForObject(Class<T> clazz, String sql, Object...args) throws Exception;
	
	List<T> queryForList(Class<T> clazz, String sql, Object... args) throws Exception;
	
	/**
	 * 有问题，弃用
	 * @param clazz
	 * @param pageable
	 * @param sql
	 * @param args
	 * @return
	 * @throws Exception
	 */
	Page<T> queryForPage(Class<T> clazz, Pageable pageable, String sql, Object... args) throws Exception;
	
	List<Map<String, Object>> queryForList(String sql, Object... args) throws Exception;
	
	Map<String, Object> queryForMap(String sql, Object... args) throws Exception;
	
	/**
	 * 有问题，弃用
	 * @param pageable
	 * @param sql
	 * @param args
	 * @return
	 * @throws Exception
	 */
	Page<Map<String, Object>> queryForPage(Pageable pageable, String sql, Object... args) throws Exception;
	
	/**
	 * 分页查询
	 * @param sql
	 * @param pageNo 页码，从1开始
	 * @param pagesize 页面条数
	 * @param args
	 * @return
	 */
	Pager getPagerBySql(final String sql, final int pageNo, final int pagesize,
			final Object... args);

}
